package com.one.group.admin.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.one.group.admin.mapper.RepairRecordMapper;
import com.one.group.model.dto.RepairRecordAddDto;
import com.one.group.model.dto.RepairRecordQueryDto;
import com.one.group.model.dto.RepairRecordUpdateDto;
import com.one.group.model.entity.RepairRecord;
import com.one.group.model.vo.RepairRecordVo;
import com.one.group.service.RepairRecordService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * {@code @Create:}  2025-09-28  14 : 52
 * {@code @Author:} Cherry
 * {@code @ToUser:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
@Service
public class RepairRecordServiceImpl extends ServiceImpl<RepairRecordMapper, RepairRecord> implements RepairRecordService {
    @Resource
    private RepairRecordMapper repairRecordMapper;


    @Override
    public void addSpRepairRecord(RepairRecordAddDto addDto) {
        RepairRecord repairRecord = RepairRecord.builder().tenantId(Convert.toLong(StpUtil.getExtra("tenant_id"))).build();

        BeanUtil.copyProperties(addDto, repairRecord, false);
        repairRecordMapper.insertSelective(repairRecord);
    }

    @Override
    public List<RepairRecordVo> listSpRepairRecords(RepairRecordQueryDto queryDto) {
        queryDto.setTenantId(Convert.toLong(StpUtil.getExtra("tenant_id")));
        List<RepairRecordVo> repairRecordVoList = repairRecordMapper.selectList(queryDto);
        return repairRecordVoList;
    }

    @Override
    public void updateSpRepairRecord(RepairRecordUpdateDto updateDto) {
        RepairRecord repairRecord = RepairRecord.builder().build();
        BeanUtil.copyProperties(updateDto, repairRecord);
        repairRecordMapper.update(repairRecord);
    }

    @Override
    public void batchDeleteSpRepairRecords(List<Long> ids) {

        repairRecordMapper.deleteBatchByIds(ids);
    }

    @Override
    public void deleteById(Long id) {

        repairRecordMapper.deleteById(id);
    }

}
